#ifndef DOUBAN_DOUMAIL_MAILVIEWER_H
#define DOUBAN_DOUMAIL_MAILVIEWER_H

#include <QPlainTextEdit>
#include <QTextBrowser>
#include <QPushButton>
#include <QLineEdit>
#include <QString>
#include <QMovie>
#include <QLabel>
class QNetworkReply;
class QDialog;

namespace Douban
{
	class Doumail;
	class DoubanContext;
	class MailViewer : public QFrame
	{
		Q_OBJECT
		public:
			void view(const Doumail*);
			void setAutoClose(bool b) { b_autoClose = b; }

			MailViewer(DoubanContext*);
			~MailViewer();
			void freeLastMail();
		protected:
			void closeEvent(QCloseEvent *event);
		private:
			DoubanContext*	m_context;
			bool			b_autoClose;
			bool			b_waitingForUserIcon;
			const Doumail*	m_currentMail;

			QLabel			senderLabel;
			QLabel			titleLabel;
			QLabel			infoLabel;
			QLabel			hintLabel;
			QLabel			loadingLabel;
			QPushButton		sendBtn;
			QTextBrowser		inText;
			QPlainTextEdit	outText;
			QLineEdit		titleText;
			QMovie			m_loadingMovie;

			QNetworkReply*	r_getMailReply;
			QNetworkReply*	r_sendMailReply;
			QNetworkReply*	r_getCatchaReply;

			QDialog*		verifyDialog;
			QLabel*			verifyLabel;
			QLineEdit*		verifyText;
			QPushButton*	verifyBtn;
			QString			captcha_token;

		private slots:
			void updateSendBtn();
			void onSendBtnClicked();
			void iconAvailable();
			void onGotMail();
			void onPostFinished();

			void updateVerifyBtn();
			void sendMailWithVerifyCode();
			void onGetCatcha();
		private:
			static const QString Doumail_Post_Entry_Plus;
			static const QString Doumail_Piece_URL;
			static const QString Doumail_Post_URL;
			static const QString Doumail_Post_Entry;
	};
}
#endif // MAILVIEWER_H
